<template>
<view class="container">
		<view class="header">
			<view class="subsection">
				<view :class=" index == subsectionCurrent?'subItem subItemCur':'subItem' " @click="subsectionChange(index)" v-for="(item, index) in subsectionList" :key="index">
					{{ item.name }}
				</view>
			</view>
			
			<!-- 统计 -->
			<view style="border-top: 1px solid #f5f5f5;border-bottom: 1px solid #f5f5f5;">
				<view style="padding: 0rpx 20rpx 10rpx 20rpx;display: flex;" >
					
					<view style="width: 50%; ">
						<view style="padding:20rpx 20rpx;" @click="onTurnoverAmount()">
							<view style="text-align: center;">
								<view style="font-size: 34rpx;font-weight: bold;line-height: 60rpx;">
									<text style="font-size: 28rpx;">￥</text>{{ sumData.turnover }}
								</view>
								<view style="font-size: 30rpx;line-height: 60rpx;">营业金额</view>
							</view>
						</view>
					</view>
					<view style="width: 50%;border-left:1px solid #e5e5e5 ">
						<view style="padding:20rpx;" @click="onSettlementAmount()">
							<view style="text-align: center;">
								<view style="font-size: 34rpx;font-weight: bold;line-height: 60rpx;">
									<text style="font-size: 28rpx;">￥</text>{{ sumData.settlementAmount || 0.00 }}
								</view>
								<view style="font-size: 30rpx;line-height: 60rpx;">到账金额</view>
							</view>
						</view>
					</view>
					
				</view>
			</view>
			<view style="text-align: center;height: 90rpx;line-height: 90rpx;position: relative;">
				<text @click="openTermPickerData()" style="font-size: 28rpx; background-color: #f5f5f5;padding: 10rpx 30rpx;border-radius: 40rpx;">
					{{ termPickerData.startTime }} 至 {{ termPickerData.endTime }}
				</text>
			</view>
		</view>
		<view class="wrapper">
			<view class="main" >
				<view style="margin: 10rpx 0rpx;" v-for="(item,index) in list" :key="index">
					<view style="padding: 0rpx 30rpx; line-height: 50rpx;display: flex;justify-items: center; " >
						<u-icon name="clock"></u-icon><text style="font-size: 33rpx;padding-left: 10rpx;">{{ item.date }}</text>
					</view>
					<view style="background-color: #ffffff;">
						<u-cell-group>
							<u-cell size="large" icon="rmb-circle" isLink iconStyle="font-size:33rpx" title="营业金额" :value="zearAmount(item.turnover)" @click="onTurnoverList(item.date, item.date)"></u-cell>
							<u-cell size="large" icon="rmb-circle" isLink iconStyle="font-size:33rpx" title="到账金额" :value="zearAmount(item.verificationAmount)" @click="onVerificationList(item.date, item.date)"></u-cell>
						</u-cell-group>
					</view>
				</view>
				
				<view class="nullData" v-if="page == 1 && list.length <=0">
					<view>
						<view>
							<image src="../../../static/image/notdata.png" class="nullImage"></image>
						</view>
						<view class="nullText">
							暂无记录
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 日期控件 -->
		<term-picker
		  :visable.sync="termPickerData.show"
		  :defaultDate="termPickerData.defaultDate"
		  :minYear="1990"
		  :timeLimit="false"
		  :deferYear="0"
		  themeColor="#1c6fc5"
		  startText="开始时间"
		  endText="结束时间"
		  @confirm="calendarConfirm">
		</term-picker>
		
		
	</view>
</template>

<script>
	import termPicker from '@/components/term-picker/term-picker.vue'
	export default {
		components:{
			termPicker
		},
		data() {
			return {
				//当前场馆
				venueId: uni.getStorageSync('venueId'),
				//当前页数
				page: 1,
				//每页显示条数
				size: 10,
				//列表数据  
				list: [],
				//总页数
				pages: 0,
				//监听滚动
				scrollTop: 0,
				realScrollTop: 0,
				refreshStatus: false,
				/**当前选择的状态序号**/
				subsectionCurrent: 0,
				/**状态分段**/
				subsectionList: [
					{status: '0',name: '今日'},
					{status: '1',name: '近七天'},
					{status: '2',name: '本月'},
					{status: '3',name: '自定义'}
				],
				//统计数据
				sumData: {
					reservationNum: 0,
					//营业金额
					turnover: "0.00",
					verificationAmount: "0.00",
					verificationNum: 0,
					//到账金额
					settlementAmount: 0
				},
				//时间筛选控件
				termPickerData: {
					//显示控件
					show: false,
					//自定义数据
					defaultDate: [],
					//选择的开始时间
					startTime: '',
					//选择的结束时间
					endTime: ''
				},
				queryParam: {
					//选择的开始时间
					startTime: '',
					//选择的结束时间
					endTime: ''
				}
			}
		},
		onLoad() {
			this.subsectionChange(0);
		},
		methods: {
			//营业金额和到账金额合计
			getHomeInfo(){
				const params = {
					venueId: this.venueId
				};
				params.startDate = this.queryParam.startTime;
				params.endDate = this.queryParam.endTime;
				params.flag = 1;//0 查首页 1查财务
				this.$request({
					url: `/blade-merchant-app/merchant-app/venue/manager/homeInfo`,
					type: 'GET',
					data: params
				}).then(res => {
					this.sumData = res.data;
				}).catch(err =>{
				})
			},
			// 获取记录 
			fetchList() {
				uni.showLoading({
					title: "加载中",
					mask: true
				})
				const params = {
					venueId: this.venueId
				};
				params.startDate = this.queryParam.startTime.substr(0,10);
				params.endDate = this.queryParam.endTime.substr(0,10);
				this.$request({
					url: `/blade-merchant-app/merchant-app/venue/manager/financeList`,
					type: 'GET',
					data: params
				}).then(res => {
					//展示数据
					uni.hideLoading();
					this.list = res.data;
				}).catch(err =>{
					uni.hideLoading();
				})
				
			},
			// 监听滚动事件
			onScroll(e) {
				this.realScrollTop = e.detail.scrollTop;
			},
			// 刷新数据
			onRefreshData() {
				this.refreshStatus = true;
				this.fetchList();
			},
			// 加载数据
			onLoadData() {
				this.fetchList();
			},
			//重新查询
			onSearchData(){
				this.page = 1;
				// this.list = [];
				this.fetchList();
			},
			//状态栏切换事件
			subsectionChange(index){
				this.subsectionCurrent = index;
				if(index == 0 || index == 1 || index == 2){
					const { startDate, endDate } = this.$utils.homeTabsDate(index);
					this.queryParam.startTime = startDate;
					this.queryParam.endTime = endDate;
					this.termPickerData.startTime=startDate.substring(0,10);
					this.termPickerData.endTime=endDate.substring(0,10);
					
					this.termPickerData.defaultDate = [startDate.substring(0,10), endDate.substring(0,10)]
					
					this.getHomeInfo();
					this.onSearchData(); 
				}
			},
			//选择时间段日期
			calendarConfirm(e){
				this.termPickerData.startTime=e[0];
				this.termPickerData.endTime=e[e.length-1];
				
				this.queryParam.startTime = e[0] +' 00:00:00';
				this.queryParam.endTime = e[e.length-1]+' 23:59:59';
				
				this.termPickerData.defaultDate = [e[0], e[e.length-1]];
				
				this.termPickerData.show = false;
				
				this.getHomeInfo();
				this.fetchList(); 
			},
			onLink(url) {
				uni.navigateTo({ url: url })
			},
			//营业金额统计
			onTurnoverAmount(){
				var startDate =  this.queryParam.startTime;
				var endDate = this.queryParam.endTime;
				this.onTurnoverList(startDate, endDate)
			},
			//到账金额统计
			onSettlementAmount(){
				var startDate =  this.queryParam.startTime;
				var endDate = this.queryParam.endTime;
				this.onVerificationList(startDate, endDate)
			},
			//点击时间段
			openTermPickerData(){
				this.subsectionCurrent = 3;
				this.termPickerData.show = true;
			},
			//营业明细
			onTurnoverList(startDate, endDate){
				this.onLink('/pagesWorkbenches/pages/financial/turnoverList/turnoverList?startDate='+(startDate.substr(0,10))+'&endDate='+(endDate.substr(0,10))+'&venueId='+this.venueId)
			},
			//到账明细
			onVerificationList(startDate, endDate){
				this.onLink('/pagesWorkbenches/pages/financial/verificationList/verificationList?startDate='+(startDate.substr(0,10))+'&endDate='+(endDate.substr(0,10))+'&venueId='+this.venueId)
			},
			//负一数据处理
			zearAmount(value){
				if(value){
					if(value == "-1"){
						return "0.00";
					}
				}
				return value;
			}
		}
	}
</script>



<style lang="scss">
	page {
		height: 100%;
		background: #f1f1f1;

		.container {
			
			.header {
				z-index: 1;
				background-color: #ffffff;
				position: sticky;
				top: 0px;
				
			
				.subsection {
					display: flex;
					background: #ffffff; 
					
					width: 100%;
					height: 60rpx;
					padding: 20rpx 0;
					
					.subItem {
						width: 33%;
						font-size: 33rpx;
						text-align: center;
					}
					
					.subItemCur {
						font-weight: 600;
						position: relative;
						padding-bottom:10rpx;
					}
					
					.subItemCur::after {
						position: absolute;
						content: ' ';
						width: 20%;
						height: 6rpx;
						bottom: 0px;
						background: red;
						left: 40%;
					}
					
				}
			}

			.wrapper {

				.main {

				}
			}
		}
		
		
		.venueForm {
			padding: 30rpx;
			
			.form-row {
				border-radius: 8rpx;display: flex;border: 1px solid #c3c3c3;justify-content: center;align-items: center; 
				
				.ftitle {
					text-align: center;
					font-size: 30rpx;
					width: 180rpx;
					display: inline-table;
					color: #333333;
					padding:0rpx 10rpx;
				}
				.fvalue {
					line-height: 80rpx;
					height: 80rpx;width: 100%;font-size: 30rpx;padding: 0rpx 20rpx;width: 100%;
				}
			
			}
			
			.height30 {
				height: 30rpx;
			}
			
			.submitBtn {
				height: 80rpx;background-color: #0544ab;color: #ffffff;line-height: 90rpx;font-size: 32rpx;
			}
			
			.bordere5e5e5 {
				border:1px solid #e5e5e5;
			}
			
			.timeCenter {
				height: 38px;line-height: 38px;width: 10%;text-align: center;
			}
			
			.clearTimeBtn {
				height: 70rpx;line-height: 70rpx;font-size:30rpx
			}
			
			.searchDiv {
				padding: 100rpx; text-align: center;
			}
			
		}
		
		.nullData {
			height: 100%;
			display: flex;
			-webkit-box-pack: center;
			justify-content: center;
			-webkit-box-align: center;
			align-items: center;
			
			.nullImage {
				width: 120px;height: 120px;
			}
			.nullText {
				color:#666666;font-size:29rpx;padding-top:15rpx;text-align: center;
			}
			
		}
	}
	
</style>